package br.usp.poli.entity;

import java.io.StringWriter;
import java.io.Writer;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import eml.ecoinformatics_org.datatable_2_0.DataTableType;

/**
 * @author Leonardo Bessa
 * 
 */
@Entity
public class DataTable {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	private String tableName;
	@Lob
	private String table;
	@Lob
	private String tableMetadata;

	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public String getTable() {
		return table;
	}

	public void setTable(String table) {
		this.table = table;
	}

	public String getTableMetadata() {
		return tableMetadata;
	}

	public void setTableMetadata(DataTableType tableType) throws JAXBException {
		JAXBContext ctx = JAXBContext.newInstance(new Class[] { DataTableType.class });
		Marshaller m = ctx.createMarshaller();
		Writer stringWriter = new StringWriter();
		m.marshal(tableType, stringWriter);
		this.tableMetadata = stringWriter.toString();
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
}
